package com.atguigu.lease.web.admin.controller.user;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.UserInfo;
import com.atguigu.lease.model.enums.BaseStatus;
import com.atguigu.lease.web.admin.service.UserInfoService;
import com.atguigu.lease.web.admin.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: liuaojun
 * @CreateTime: 2025-02-22
 * @Description:
 * @Version: 1.0
 */
@Tag(name = "用户信息管理")
@RestController
@RequestMapping("/admin/user")
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;

    @Operation(summary = "根据条件分页查询用户列表")
    @GetMapping("page")
    public Result<IPage<UserInfo>> page(@RequestParam Integer current, @RequestParam Integer size, UserInfoQueryVo vo){
        IPage<UserInfo> userInfoIPage = new Page<>(current,size);
        LambdaQueryWrapper<UserInfo> userInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userInfoLambdaQueryWrapper.eq(UserInfo::getPhone, vo.getPhone());
        userInfoLambdaQueryWrapper.eq(UserInfo::getStatus,vo.getStatus());
        IPage<UserInfo> page = userInfoService.page(userInfoIPage, userInfoLambdaQueryWrapper);
        return Result.ok(page);
    }

    @Operation(summary = "根据ID更新用户状态")
    @PostMapping("updateStatusById")
    public Result updateStatusById(@RequestParam Long id, @RequestParam BaseStatus status){
        LambdaUpdateWrapper<UserInfo> userInfoLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        userInfoLambdaUpdateWrapper.eq(UserInfo::getId,id);
        userInfoLambdaUpdateWrapper.set(UserInfo::getStatus,status);
        userInfoService.update(userInfoLambdaUpdateWrapper);
        return Result.ok();
    }
}
